package com.apps.ftapp.act;

import android.os.Bundle;
import android.view.WindowManager;

import com.apps.ftapp.R;
import com.apps.ftapp.activity.BaseActivity;
import com.apps.ftapp.util.Constant;
import com.apps.ftapp.util.L;
import com.duobeiyun.bean.ChatBean;
import com.duobeiyun.callback.LiveMessageCallback;
import com.duobeiyun.player.LivePlayer;
import com.duobeiyun.type.RoleType;
import com.duobeiyun.widget.LivePlayerView;

import org.json.JSONObject;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ZhiBoActivity extends BaseActivity implements LiveMessageCallback {

    @BindView(R.id.playbackPlayer)
    LivePlayerView playbackPlayerView;


    private String roomId;
    private String nickname;
    private LivePlayer playbackPlayer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zhi_bo);
        ButterKnife.bind(this);

        Bundle bundle = this.getIntent().getExtras();
        roomId = bundle.getString("roomId");
        nickname = bundle.getString("nickname");

        setTitle("" + bundle.getString("title"));
        L.i("main", ":========:::" + roomId + "::::" + nickname);


        initPlayerAndSetCallback();
    }


    public void initPlayerAndSetCallback() {
        playbackPlayer = new LivePlayer(this.getApplicationContext(), playbackPlayerView);
        L.i("main", "uid:" + Constant.uid);
        L.i("main", "pid:" + Constant.PID);
        L.i("main", "appkey:" + Constant.APPKEY);
        L.i("main", "nickname:" + nickname);
        L.i("main", "roomId:" + roomId);
//        JYVideoView tearchImg = new JYVideoView(getApplicationContext());
//        tearchImg.setImageResource(R.mipmap.ic_launcher);
        playbackPlayer.setVideoView(null, null);
        playbackPlayer.setAuth(Constant.PID, Constant.APPKEY);
        playbackPlayer.setPlayInfo(Constant.uid, roomId, nickname, RoleType.ROLE_TYPE_STUDENT, true, this);
    }


    @Override
    protected void onStart() {
        super.onStart();
        if (playbackPlayer != null) {
            playbackPlayer.start();
        }
    }

    @Override
    protected void onPause() {
        if (playbackPlayer != null) {
            playbackPlayer.pause();
        }
        super.onPause();
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (playbackPlayer != null) {
            playbackPlayer.release();
        }
    }


    //开始加载
    @Override
    public void loading() {

    }

    //返回单条信息
    @Override
    public void handleContent(ChatBean chatBean) {

    }

    //返回聊天列表
    @Override
    public void handleContent(ArrayList<ChatBean> arrayList) {

    }

    //段开重连，清理上次的聊天记录
    @Override
    public void handleClearChat() {

    }

    @Override
    public void statusCode(int i, String s) {

    }

    //公告信息
    @Override
    public void handleAnnounceMessage(String s) {

    }

    //连接成功
    @Override
    public void connected() {

    }

    //
    @Override
    public void connectFail(String s) {

    }


    //重新登录
    @Override
    public void kickoff() {

    }

    //网络未连蛸
    @Override
    public void networkNotConnected() {

    }

    //投票开始
    @Override
    public void voteStart(int i) {

    }

    //投票结束
    @Override
    public void voteEnd() {

    }

    //投票关闭
    @Override
    public void voteClose() {

    }

    //投票数据
    @Override
    public void voteInfo(JSONObject jsonObject) {

    }

//    //状态码
//    @Override
//    public void statusCode(int i) {
//
//        L.i("main", "状态码:" + i);
//    }


    //老师在线
    @Override
    public void teacherOnline() {

    }

    //ppt相关信息
    @Override
    public void pptMessage(int i, int i1) {

    }

    //在线人数
    @Override
    public void onlineUserCount(int i) {

    }
}
